/**    
 * @{#} LogAdvisor.java Create on 2012-4-29 下午11:43:50    
 *    
 * Copyright (c) 2012 by 悠忧虫.    
 *    
 * @author 悠忧虫
 * @version 1.0    
 */
package tk.sunlatus.project.common.aop;

import java.util.Arrays;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;

/**
 * @{# LogAdvisor.java Create on 2012-4-29 下午11:43:50
 * 
 *     类功能说明:
 * 
 *     <p>
 *     Copyright: Copyright(c) 2012
 *     </p>
 * @Version 1.0
 * @Author 悠忧虫
 */
public class SunlatusLogger implements MethodInterceptor {

    private Logger logger = null;

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        try {
            // TODO Auto-generated method stub
            Object result = null;
            Class<?> clazz = invocation.getThis().getClass();
            logger = Logger.getLogger(clazz);
            logger.info("enter method " + invocation.getMethod().getName());
            logger.info("args:" + Arrays.toString(invocation.getArguments()));
            result = invocation.proceed();
            logger.info("Exit method " + invocation.getMethod().getName());
            return result;
        } catch (Throwable e) {
            logger.error("process method " + invocation.getMethod() + " failed.");
            logger.error(e);
            throw e;
        }
    }
}
